package net.fdukedom.epicurus.plugin;

import net.fdukedom.epicurus.domain.entity.Plugin;
import net.fdukedom.epicurus.domain.entity.Action;

import java.util.Map;
import java.util.Set;

/**
 * @author Dmitry Y. Kochelaev
 */
public class ActionsLoader extends CollectionLoader<Plugin, Action> {
    public ActionsLoader(Plugin plugin) {
        super(plugin);
    }

    public Action parseAttributes(Map<String, String> attributes) {
        return new Action(attributes.get("name"), item);
    }

    public Set<Action> getLoadedCollection() {
        return item.getActions();
    }

    public void disposeElement(Action element) {
        item.getActions().remove(element);
        element.setPlugin(null);
    }

    public void addElement(Action element) {
        element.setPlugin(item);
        item.getActions().add(element);
    }
}
